import React, { memo,Component } from 'react'
import { Image,Avatar,Button,Input,Select,Table  } from 'antd';
import './index.less'
import {getParam} from '../../utils/tool'
import {baseUrl} from '../../assets/baseUrl'
import {emailDetail} from '@/api/user'
import { withRouter } from "react-router-dom";
import { Upload, Modal,message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import TurnBack from '../../components/pageComponents/turnBack'
import TextFlow from './component/textFlow';
import {formatDate} from '../../utils/tool'
import TemplateOne from './component/EmailTemplate/template_one'
import TemplateTwo from './component/EmailTemplate/template_two';
const BaseUrl = baseUrl()

class myEailDetail extends Component{
    constructor(props) {
        super(props);
        this.state = {
            detail: null, //邮件详情
            backUrl: null
        }
    }
    componentDidMount(){
        this.getEmailDetail()
        this.setState({
            backUrl: `/home/myCenter/myEmail?tabKey=${getParam(this.props.location.search,'tabKey')}`
        })
    }

    //获取邮箱历史
    getEmailDetail=()=>{
        let data = {
            mailId:getParam(this.props.location.search,'mailId'),
            tabKey:getParam(this.props.location.search,'tabKey'),
            studentId:getParam(this.props.location.search,'studentId')
        }
        emailDetail(data).then(res=>{
            console.log(res.data?.message[0],'');
            this.setState({
                detail:res.data?.message[0]
            })
        })
    }

    render(){
        const {detail} = this.state  
        return (
            <div className='myEail-detail'>
                <TurnBack url={this.state.backUrl} />
                <div className="messbox">
                    <ul>
                        <li><span className='label'>发送人：</span>&emsp;<span className='inner'>{detail?.senderNick}</span></li>
                        <li><span className='label'>发送时间：</span><span className='inner'>{detail?.sendTime}</span></li>
                        <li><span className='label'>过期时间：</span><span className='inner'>{formatDate(detail?.expTime*1000)}</span></li>
                        <li><span className='label'>标&emsp;&emsp;题：</span><span className='inner'>{detail?.title}</span></li>
                        <li><span className='label'>邮件内容：</span><span className='inner'>{detail?.content && <TextFlow text={detail?.content} clamp={1} width={600}></TextFlow>}</span>
                          {detail?.mailType==1&&<TemplateOne extra={detail.extra}/>} 
                          {detail?.mailType==2&&<TemplateTwo extra={detail.extra}/>} 
                        </li>
                    </ul>
                </div>
            </div>
        )
    }
}
export default withRouter(myEailDetail)